import ProduList from "@/components/subject/ProduList.vue";
import ProdulistLine from "@/components/subject/ProdulistLine.vue";
class Index {
  mixin = {
    components: {
      ProduList,
      ProdulistLine
    },
    data() {
      return {
        title: "Miss Yeah"
      }
    },
    head() {
      return {
        title: "missyeah",
        meta: [{
            hid: "keyword",
            name: "keyword",
            content: `missyeah`,
          },
          {
            hid: "description",
            name: "description",
            content: `missyeah`,
          },
        ],
        link: [{
          rel: "canonical",
          href: "https://www.missyeah.com" + this.$route.fullPath,
        }, ],
      }
    },
    async asyncData(that) {
      //首页配置默认设置,后台自由块获取
      let freeblock = {
        //首页商品列表
        index_goods: [],
        //首页商品标题
        index_goods_title: "Grab the most wanted!",
      };
      for(let i=1;i<=10;i++){
        freeblock['index_banner_'+i]=[];
      }
      //广告栏位，后台广告列表获取
      let advert = {
        //首页顶部广告图
        index_adverts_top: [],
        //首页底部部广告图
        index_adverts_bottom: [],
      };
      let block_tag = [];
      for (let key in freeblock) {
        //遍历首页自由块标签
        block_tag.push(key + "");
      }
      let advert_tag = [];
      for (let key in advert) {
        //遍历首页自由块标签
        advert_tag.push(key + "");
      }
      let
        resFreeblock = {},
        resAdverts = {};
      try {
        [resFreeblock, resAdverts] = await Promise.all([
          //获取首页配置,自由块
          that.store.dispatch("over/freeblock", {
            block_tag: block_tag,
          }),
          //广告图片
          that.store.dispatch("over/adverts", {
            tag: advert_tag,
          }),
        ]);
      } catch (err) {
        console.log(err);
      }
      let freeblockInfo = freeblock;
      let advertsInfo = advert;
      if (resFreeblock.data)
        if (resFreeblock.data.info)
          freeblockInfo = resFreeblock.data.info;

      if (resAdverts.data)
        if (resAdverts.data.info)
          advertsInfo = resAdverts.data.info;
      return {
        freeblock: freeblockInfo,
        adverts: advertsInfo,
      }
    },
    mounted() {
      this.getCountryList();
      let index = 0;
    },
    methods: {
      //获取国家列表
      getCountryList() {
        this.$store.dispatch("over/cotuntryList", {});
      },
    }
  }
}
export default new Index();
